package action_行为型.chain_of_responsibility_pattern_责任链模式;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: hihi
 * @Date: 2020/07/07/16:52
 * @Description:
 */
public abstract class AbstractLogger {
	public static final int INFO = 1;
	public static final int DEBUG = 2;
	public static final int ERROR = 3;

	protected int level;

	//下一个处理器
	protected AbstractLogger nextAbstractLogger;

	public void setNextAbstractLogger(AbstractLogger nextAbstractLogger) {
		this.nextAbstractLogger = nextAbstractLogger;
	}

	public void logMessage(int level, String message) {
		if (this.level <= level) {
			write(message);
		}
		if (null != nextAbstractLogger) {
			nextAbstractLogger.logMessage(level, message);
		}
	}

	abstract protected void write(String message);
}
